﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Services;
using IRepositories;
using System.Web.Mvc;
using IServices;
using UniversityManagerWebSite.Models.Validation;
using GestionLinqLibData;

namespace UniversityManager.Tests
{
    /// <summary>
    /// Description résumée pour EleveServiceTest
    /// </summary>
    [TestClass]
    public class EleveServiceTest
    {
        private Mock<IEleveRepository> _mockRepository;
        private ModelStateDictionary _modelState;
        private IEleveService _service;

        [TestInitialize]
        public void Initialize()
        {
            _mockRepository = new Mock<IEleveRepository>();
            _modelState = new ModelStateDictionary();
            _service = new EleveService(new ModelStateWrapper(_modelState), _mockRepository.Object);
        }
        [TestMethod]
        public void CreateEleve()
        {
            //Arrange
            eleve _eleve = new eleve { nom_eleve = "boujerida", note = null, num_inscription = 1, prenom_eleve = "haithem" };
            //Act
            var result = _service.CreateEleve(_eleve);
            //Assert
            Assert.IsTrue(result);
        }

        [TestMethod]
        public void CreateEleveRequiredNom()
        {
            //Arrange
            eleve _eleve = new eleve { nom_eleve = string.Empty, note = null, num_inscription = 1, prenom_eleve = "haithem" };

            //Act
            var result = _service.CreateEleve(_eleve);

            //Assert
            Assert.IsFalse(result);
            var error = _modelState["nom_eleve"].Errors[0];
            Assert.AreEqual("nom nul", error.ErrorMessage);
        }
        [TestMethod]
        public void CreateEleveRequiredPrenom()
        {
            //Arrange
            eleve _eleve = new eleve { nom_eleve = "boujerida", note = null, num_inscription = 1, prenom_eleve = String.Empty };

            //Act
            var result = _service.CreateEleve(_eleve);

            //Assert
            Assert.IsFalse(result);
            var error = _modelState["prenom_eleve"].Errors[0];
            Assert.AreEqual("prenom nul", error.ErrorMessage);
        }


      

    }
}